//
//  StellGoodsListViewModel.m
//  GLGW_Shoping
//
//  Created by yang on 2018/12/11.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "StellGoodsListViewModel.h"
#import "StellGoodsListTableViewCell.h"
#import "GoodsTopSelectView.h"
#import "AdressAndSortingView.h"
#import "ScreeningView.h"

@interface StellGoodsListViewModel ()<UITableViewDelegate,UITableViewDataSource,GoodsTopDelegate>
{
    AdressAndSortingView * screeningView;
    ScreeningView * screenView;
}
@property (nonatomic,strong) UIView * self_View;
@end

@implementation StellGoodsListViewModel

-(instancetype)initWithViewToViewModel:(UITableView *)tableView theSuperView:(UIView *)superView{
    if (self = [super initWithViewToViewModel:tableView theSuperView:superView]) {
        self.self_View = superView;
        tableView.y = tableView.y + kHeightProportion_In_iPhoneTriploid(34);
        tableView.height = tableView.height - kHeightProportion_In_iPhoneTriploid(34);
        tableView.dataSource = self;
        tableView.delegate = self;
        tableView.rowHeight = kHeightProportion_In_iPhoneTriploid(136);
        tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, kHeightProportion_In_iPhoneTriploid(10))];
        [superView addSubview:tableView];
        //
        GoodsTopSelectView * topView = [[GoodsTopSelectView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, kHeightProportion_In_iPhoneTriploid(34)) inSuperView:superView];
        topView.delegate = self;
    }
    return self;
}

#pragma maek -- UITableViewDelegate,UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    StellGoodsListTableViewCell * cell = [StellGoodsListTableViewCell cellWithTableView:tableView];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.delegate && [self.delegate respondsToSelector:@selector(stellChangeDidSelectRowAtIndexPath:)]) {
        [self.delegate stellChangeDidSelectRowAtIndexPath:indexPath];
    }
}

#pragma mark ----- GoodsTopDelegate
-(void)selectTopViewButTag:(NSInteger)tag_num{
    if (screenView || screeningView) {
        [screeningView dissmiss];
        [screenView dissmiss];
    }
    switch (tag_num) {
        case 180:{
            screeningView = [[AdressAndSortingView alloc] initWithFrame:CGRectMake(0, kHeightProportion_In_iPhoneTriploid(35), KScreenWidth, KScreenHeight - kHeightProportion_In_iPhoneTriploid(35)) theTableListType:ListType_AllAdress inSuperView:self.self_View];
        }
            break;
        case 181:{
            screeningView = [[AdressAndSortingView alloc] initWithFrame:CGRectMake(0, kHeightProportion_In_iPhoneTriploid(35), KScreenWidth, KScreenHeight - kHeightProportion_In_iPhoneTriploid(35)) theTableListType:ListType_Comprehensive inSuperView:self.self_View];
        }
            break;
        case 182:{
            CGFloat sc_height;
            if (iPhoneX) {
                sc_height = KScreenHeight - kHeightProportion_In_iPhoneTriploid(35) - 88 - kHeightProportion_In_iPhoneTriploid(34);
            }else{
                sc_height = KScreenHeight - kHeightProportion_In_iPhoneTriploid(35) - 64;
            }
            screenView = [[ScreeningView alloc] initWithFrame:CGRectMake(0, kHeightProportion_In_iPhoneTriploid(35), KScreenWidth, sc_height) inSuperView:self.self_View];
            
        }
            break;
            
        default:
            break;
    }
}

@end
